package com.wxb.cardmis.service.impl;

import com.wxb.cardmis.entity.UserEntity;
import com.wxb.cardmis.repository.UserRepository;
import com.wxb.cardmis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

/**
 * All rights Reserved, Designed By www.super-master.cn
 *
 * @ProjectName: cardmis
 * @Package: com.wxb.cardmis.service.impl
 * @ClassName: UserServiceImpl
 * <p> </p>
 * @Author: [Wei Xiao]
 * @Date: 2022/2/21 17:53
 * @Version: V1.0
 * @Copyright: 2022  com.wei All rights reserved.
 * TODO: 注意,本文件Wei Xiao所作,如果转载或使用请标明具体出处!
 * @Date: 2022年02月21日 17:53
 * @Description: []
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;
    //注册
    @Override
    public String register(UserEntity requestUser) {
        UserEntity user = userRepository.findByUname(requestUser.getUname());

        if (user != null){
            return "no";
        }else {
            userRepository.save(requestUser);
            return "yes";
        }
    }
    //登录
    @Override
    public String login(UserEntity requestUser, HttpSession session) {
        UserEntity user = userRepository.findByUnameAndUpwd(requestUser.getUname(),requestUser.getUpwd());
        if (user != null){
            session.setAttribute("user",user);
            return "ok";
        }
        return "no";
    }

    @Override
    public UserEntity getAuser() {
        return userRepository.getById(1);
    }
}
